﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using BusinessLayer;

namespace BoletoElectronicoDesktop.CargaCredito
{
    public partial class FormCargaCredito : FormAddModify
    {
        public FormCargaCredito(Util.Funcionalidad use): base(use)
        {
            InitializeComponent();
            txtFecha.Text = DateTime.Now.ToString("dd/MM/yyyy");
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Dispose();
            Close();
        }

        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (camposObligatorios())
            {
                Int32 numTarjeta = Convert.ToInt32(txtNroTarjeta.Text);
                decimal monto = Convert.ToDecimal(txtMonto.Text);
                DateTime date = DateTime.Now;

                bool goal = BizCarga.cargarCredito(numTarjeta, monto, date);
                if (goal)
                {
                    txtMessage.Text = "La carga se completó exitosamente";
                    clearAll();
                }
                else
                {
                    txtMessage.Text = "La tarjeta no existe o esta inhabilitada.";
                }
            }
        }

        private bool camposObligatorios()
        {
            bool validate = true;
            StringBuilder sb = new StringBuilder();
            if (String.IsNullOrEmpty(txtNroTarjeta.Text))
            {
                sb.AppendLine("Debe ingresar el número de tarjeta");
                validate = false;

            }
            if (String.IsNullOrEmpty(txtMonto.Text))
            {
                sb.AppendLine("Debe ingresar un monto.");
                validate = false;
            }
            txtMessage.Text = sb.ToString();
            return validate;
        }

        private void clearAll()
        {
            txtMonto.Text = String.Empty;
            txtNroTarjeta.Text = String.Empty;
        }

        private void txtNroTarjeta_KeyPress(object sender, KeyPressEventArgs e)
        {
            Util.limitarCampoNumericoEntero(e);
        }
    }
}
